// 导入讯飞星火大模型的SDK
import {ChatMessage, ModelVersion, SparkClient} from "spark-node-sdk";

const model = ModelVersion.V3;
const client = new SparkClient('0cf25797', '57f5cccf8746ea57fb52a3399d8f31c0', 'ZTgzMDM3MmY4YTdlNTFkZTI1MDc2N2Qw');

// export一个方法
export async function ask(text) {
    const messages = [
        ChatMessage.fromUser(text)
    ];
    let contents = "";
    try {
        const generator = await client.chatAsStreamAsync(model, messages);
        for await (const message of generator) {
            contents += message.text;
        }
    } catch (e) {
        console.log("出现错误", e);
    }
    return contents;
}
